function Index_Exist = CheckANAC_V(OP, K, S0, CPFlag)
% The code is based on the following paper:
%   Chen, T. Y., Lin, Y. L., and Tzeng, L. Y., forthcoming.
%   Estimating probability weighting functions through option pricing bounds. Review of Asset Pricing Studies.
%
% Copyright: Tzu-Ying Chen, Yo-Lan Lin, Larry Y. Tzeng
% Date: January 30, 2024

Index_Exist = 1:1:length(K);    
for n = 1:length(K)
    if length(Index_Exist) >= 2
        AllCOMB = nchoosek(Index_Exist, 2);
        AllCOMB_Score = diff(OP(AllCOMB)')';
    
        if CPFlag==1
            AllCOMB = AllCOMB(AllCOMB_Score >= 0, :);                           
        else
            AllCOMB = AllCOMB(AllCOMB_Score <= 0, :);                                  
        end
        Record_Vertical = accumarray(AllCOMB(:), 1, size(K), @sum, nan);  
        Record_Vertical(isnan(Record_Vertical)) = 0;                       

        if sum(Record_Vertical)==0
            break
        else
        end
    
        if sum(Record_Vertical) > 0
            Index_Drop = find(Record_Vertical==max(Record_Vertical));

            if length(Index_Drop) > 1
                [~, Index_Far] = max(abs(K(Index_Drop) / S0 - 1));
                Index_Drop = Index_Drop(Index_Far);                           
            else
            end
            Index_Exist(Index_Exist==Index_Drop) = [];                     
        else
        end
    else
        break
    end
end